import moment from 'moment';

export const shortTime = function(value) {
  return moment(value).format('YYYY-MM-DD');
}

export const time = function(value) {
  return moment(value).format('YYYY-MM-DD HH:mm:ss');
}

export const leaveTime = function(value) {
  return moment(value).format('YYYY-MM-DD HH:mm');
}

export const monthTime = function(value) {
  return moment(value).format('YYYY-MM');
}

export const secondsTime = function(value) {
  return moment(value).format('HH:mm:ss');
}

export const filterTime = (time, type = 'short') => {
  if (type === 'short') {
    return moment(time).format('YYYY-MM-DD')
  } else {
    return moment(time).format('YYYY-MM-DD HH:mm:ss')
  }
}

export const startOfDate = function(d, dateType = 'day') {
  return moment(d).startOf(dateType)
}

export const endOfDate = function(d, dateType = 'day') {
  return moment(d).endOf(dateType)
}

export const lastDateofMonth = function(d) {
  var firstDate = moment(d).startOf('month').format('YYYY-MM-DD');
  var endDate = moment(d).endOf('month').format('YYYY-MM-DD');
  var Datearr = [];
  Datearr.push(firstDate);
  Datearr.push(endDate);
  return Datearr;
}

// 获取给定日期的 n个月后的日期  给定日期格式如：val = 2019-02-26; n = 多少个月
export const computeYmd = function(sourceDate, monthNum) {
  return moment(sourceDate).add(monthNum, "months").format("YYYY-MM-DD")
}
